import os

# 设置 PYARROW_IGNORE_TIMEZONE 环境变量
os.environ['PYARROW_IGNORE_TIMEZONE'] = '1'

import pandas as pd
pd.set_option('display.max_rows', None)  # 设置显示最大行数为无限
pd.set_option('display.max_columns', None)  # 设置显示最大列数为无限
pd.set_option('display.width', None)  # 自动检测控制台的宽度

# 现在导入 featuretools
import featuretools as ft

# 加载示例数据集
data = ft.demo.load_mock_customer()

# 获取数据框
customers_df = data["customers"].head(2)
sessions_df = data["sessions"].head(3)
transactions_df = data["transactions"].head(4)

# 打印数据框的前几行
print("Customers DataFrame:")
# print(customers_df.head(10))
print(customers_df)
print("\nSessions DataFrame:")
# print(sessions_df.head())
print(sessions_df)
print("\nTransactions DataFrame:")
# print(transactions_df.head())
print(transactions_df)


dataframes = {
    "customers": (customers_df, "customer_id"),
    "sessions": (sessions_df, "session_id", "session_start"),
    "transactions": (transactions_df, "transaction_id", "transaction_time"),
}

relationships = [
    ("sessions", "session_id", "transactions", "session_id"),
    ("customers", "customer_id", "sessions", "customer_id"),
]


feature_matrix_customers, features_defs = ft.dfs(
    dataframes=dataframes,
    relationships=relationships,
    target_dataframe_name="customers",
)
feature_matrix_customers.head(1)

print(feature_matrix_customers)


feature_matrix_sessions, features_defs1 = ft.dfs(
    dataframes=dataframes, relationships=relationships, target_dataframe_name="sessions"
)
feature_matrix_sessions.head(5)

feature = features_defs[18]
feature

# ft.graph_feature(feature)

ft.describe_feature(feature)